//
//  CNSwitch.swift
//  Voice
//
//  Created by 卢逢卫 on 2024/3/12.
//

import UIKit


extension UISwitch {
    public static func cn_initWith(isOn: Bool, onColor: UIColor?, thumbColor: UIColor?, scale: CGFloat) -> UISwitch {
        let customSwitch = UISwitch()
        customSwitch.isOn = isOn
        customSwitch.tintColor = onColor
        customSwitch.onTintColor = onColor
        customSwitch.thumbTintColor = thumbColor
        customSwitch.transform = CGAffineTransform(scaleX: scale, y: scale)
        return customSwitch
    }
}

extension UISwitch {
    public func cn_setImage(onImage: UIImage?, offImage: UIImage?) {
        self.onImage = onImage
        self.offImage = offImage
    }

    public func cn_toggleSwitch() {
        self.setOn(!self.isOn, animated: true)
    }
}
